/*
 * Javlov - a Java toolkit for reinforcement learning with multi-agent support.
 * 
 * Copyright (c) 2009 Matthijs Snel
 * 
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
package net.javlov.world.ui;

import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.geom.AffineTransform;

import net.javlov.world.AgentBody;
import net.javlov.world.PhysicalSensor;
import net.javlov.world.Sensor;
import net.javlov.world.Body;

public class AgentBodyView extends BodyView {
	
	protected static boolean drawSensors = false;
	
	public static boolean isDrawSensorsEnabled() {
		return drawSensors;
	}
	
	public static void setDrawSensorsEnabled(boolean draw) {
		drawSensors = draw;
	}
	
	
	public AgentBodyView() {}
	
	public AgentBodyView(Body model) {
		setModel(model);
	}
	
	@SuppressWarnings("unchecked")
	public void draw( Graphics g) {
		Graphics2D g2d = (Graphics2D) g;
		g2d.setColor(Color.black);
		
		java.awt.Shape txShape;
		AffineTransform at = getBodyTransform();
		txShape = at.createTransformedShape(model.getFigure());
		g2d.draw(txShape);
		
		if ( drawSensors ) {
			//Graphics2D g2d = (Graphics2D) g;
			g2d.setColor(Color.red);
			//TODO: not nice
			for ( Sensor s : ((AgentBody) model).getSensors() ) {
				if ( s instanceof PhysicalSensor )
					g2d.draw( ((PhysicalSensor) s).getRangeArea() );
			}
		}
	}
}
